package io.renren.modules.m.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.matlist.entity.MatlistEntity;
import io.renren.modules.pallettable.service.PallettableService;
import io.renren.modules.poschangerecord.entity.PreposEntity;
import io.renren.modules.user.entity.UserinfoEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.m.entity.MaterialEntity;
import io.renren.modules.m.service.MaterialService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

@RestController
@RequestMapping("m/material")
public class MaterialController {
    @Autowired
    private MaterialService materialService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("m:material:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = materialService.queryPage(params);
        // 分页
//        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
//        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
//        String pid = String.valueOf(params.get("key"));
//        Page<MaterialEntity> page = new Page<>(pageIndex,pageSize);
//
//        // 通过调用自定义dao层实现
//        materialService.selectByPid(pid,page);


        return R.ok().put("page", page);
    }

    @GetMapping("getMaterial")
    public List<MaterialEntity> getMaterial(@RequestParam("matid") String matid){
        return materialService.getMaterial(matid);
    }

    /**
     * 托盘内物料
     */
    @GetMapping(value = "/listMaterial",produces = {"application/json;charset=UTF-8"})
    public List<MaterialEntity> listMaterial(){
        return materialService.listMaterial();
    }

    /**
     * 物料信息
     */
//    @GetMapping("getMat")
//    public List<PreposEntity> getMat(){
//        return poschangerecordtableService.getMat();
//    }


    @GetMapping(value = "/num",produces = {"application/json;charset=UTF-8"})
    public List listNum(){
        return materialService.listNum();
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{mid}")
    @RequiresPermissions("m:material:info")
    public R info(@PathVariable("mid") String mid){
		MaterialEntity material = materialService.getById(mid);

        return R.ok().put("material", material);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("m:material:save")
    public R save(@RequestBody MaterialEntity material){
		materialService.save(material);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("m:material:update")
    public R update(@RequestBody MaterialEntity material){
		materialService.updateById(material);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("m:material:delete")
    public R delete(@RequestBody String[] mids){
		materialService.removeByIds(Arrays.asList(mids));

        return R.ok();
    }

}
